<?php 
	
	session_start();
	
	if(isset($_POST["ajouter"])){
		
		$alc["nom"] = $_REQUEST["nomInput"];
		$alc["type"] = $_REQUEST["typeInput"];
		$alc["provenance"] = $_REQUEST["provenanceInput"];
		$alc["annee"] = $_REQUEST["anneeInput"];
		$alc["tauxAlcool"] = $_REQUEST["alcoolInput"];
		$alc["qty"] = $_REQUEST["bouteillesInput"];
		$alc["favoris"] = @$_REQUEST["favoriInput"] == "oui" ? true : false;
		$alc["cote"] = $_REQUEST["coteInput"];
		$alc["description"] = $_REQUEST["descriptionInput"];
		$alc["notes"] = $_REQUEST["noteInput"];
		$alc["image"] = basename( $_FILES["photoInput"]["name"]);
		$alc["rabais"] = false;
		
		
		$temp = explode($_SERVER['SCRIPT_FILENAME'], "/");
		$imagePath = "";
		for ($i=0;$i<count($temp)-1;$i++)
		{
			$imagePath = $imagePath . $temp[$i] . "/";
		}
		$imagePath = $imagePath . "images/";
		
		$target_path = $imagePath;

		$target_path = $target_path . $alc["image"]; 

		if(move_uploaded_file($_FILES['photoInput']['tmp_name'], $target_path)) {
			echo "Le fichier ".  basename( $_FILES['photoInput']['name']). 
			" a été chargé avec succès";
		} else{
			echo "Une erreur s'est produite. Veuillez réessayer!";
		}
		
		echo "<pre>";
		print_r($alc);
		echo "</pre>";
		
		$_SESSION["profils"][$_SESSION["profilActuel"]]["inventaires"][$_REQUEST["iid"]]["bouteilles"][] = $alc;

		header("Location: inventaire.php?iid=".$_REQUEST["iid"]);
	}
	
	
	include 'include/header.php';
?>
		<div id="contenu">
			<h1>Ajouter un alcool</h1>
			<form id="alcoolForm" action="ajoutAlcool.php" enctype="multipart/form-data" method="post">
			
			<input type="hidden" name="iid" value="<?php echo $_REQUEST["iid"]; ?>">
			
			<div class="infos">
				<div class="photo">
					<p><label for="photoInput">Ajouter une photo:</label></p>
					<p><input type="file" id="photoInput" name="photoInput" /></p>
				</div>
				<div class="infosGenerales">
					<div class="ligne">
						<label for="nomInput">Nom:</label><input type="text" id="nomInput" name="nomInput" />
					</div>
					<div class="ligne">
						<label for="typeInput">Type:</label>
						<select id="typeInput" name="typeInput" >
							<option value="Bière">Bière</option>
							<option value="Spiritueux">Spiritueux</option>
							<option value="Vin blanc">Vin blanc</option>
							<option value="Vin rouge">Vin rouge</option>
						</select>
					</div>
					<div class="ligne">
						<label for="anneeInput">Millésime:</label><input type="text" id="anneeInput" name="anneeInput" />
					</div>
					<div class="ligne">
						<label for="provenanceInput">Provenance:</label><input type="text" id="provenanceInput" name="provenanceInput" />
					</div>
					<div class="ligne">
						<label for="alcoolInput">% d'alcool:</label><input type="text" id="alcoolInput" name="alcoolInput" />
					</div>
					<div class="ligne">
						<label for="bouteillesInput">Nombre de bouteilles:</label><input type="text" id="bouteillesInput" name="bouteillesInput" />
					</div>
					<div class="ligne">
						<label for="favoriInput">Favori:</label><input type="checkbox" id="favoriInput" name="favoriInput" value="oui" />
					</div>
					<div class="ligne">
						<label for="coteInput">Cote:</label>
						<select id="coteInput" name="coteInput" >
							<option value="0">0</option>
							<option value="1">1</option>
							<option value="2">2</option>
							<option value="3">3</option>
							<option value="4">4</option>
							<option value="5">5</option>
						</select>
					</div>
					
				</div>
			</div>
			<div class="description">
				<h2><label for="descriptionInput">Description</label></h2>
				<textarea rows="5" cols="80" id="descriptionInput" name="descriptionInput" ></textarea>
			</div>
			<div class="note">
				<h2><label for="noteInput">Note de dégustation</a></h2>
				<textarea rows="5" cols="80" id="noteInput" name="noteInput" ></textarea>
			</div>
			<input type="submit" value="Ajouter" name="ajouter" id="ajouter" />
			</form>
		</div>
	</body>

</html>